﻿namespace _1_数据类型;

internal enum Days
{
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
}

internal class Program
{
    private static void Main(string[] args)
    {
        #region 1_布尔类型

        //Random r = new Random();
        //// r.Next(0, 2) -> 0 或 1, 也就是左闭右开
        //bool b = Convert.ToBoolean(r.Next(0, 2));
        //Console.WriteLine(b);
        //if (b)
        //{
        //    Console.WriteLine("this is a boy, we will use John");
        //}
        //else 
        //{
        //    Console.WriteLine("this is a girl, we will use Victoria");
        //}

        #endregion

        #region 2_整数

        ////C#别名 .NET类型       尺寸      范围
        ////sbyte System.SByte    1 个字节 - 128 至 127
        ////byte System.Byte 1 个字节   0 至 255
        ////short System.Int16    2 字节 - 32,768 至 32,767
        ////ushort System.UInt16   2 个字节   0 至 65,535
        ////int System.Int32    4 字节 - 2,147,483,648 至 2,147,483,647
        ////uint System.UInt32   4 个字节   0 至 4,294,967,295
        ////long System.Int64    8 字节 - 9,223,372,036,854,775,808 至 9,223,372,036,854,775,807
        ////ulong System.UInt64   8 个字节   0 至 18,446,744,073,709,551,615

        //// 使用下划线字符, 来提高这个值的可读性
        //var num1 = 234_321_000; // 等于234321000
        //Console.WriteLine(num1);
        //var num2 = 0b_0110_000_100;
        //Console.WriteLine(num2);

        #endregion

        #region 3_算术溢出

        //sbyte sb = 126;
        //sb++;
        //Console.WriteLine(sb); // 127
        //sb++;
        //// 发生溢出时，变量将重置为该数据类型的下限
        //Console.WriteLine(sb); // 会重置为最小的值, 也就是-128

        #endregion

        #region 4_浮点数

        //C# 别名	.NET 类型	大小	精度	范围
        //float System.Single   4 字节    7 位数 + -1.5 x 10 ^ -45 至 + -3.4 x 10 ^ 38
        //double System.Double   8 字节    15 - 16 位数字 + -5.0 x 10 ^ -324 至 + -1.7 x 10 ^ 308
        //decimal System.Decimal  16 字节 小数点后 28 - 29 位 + -1.0 x 10 至 + -7.9 x 10 ^ 28

        // C#中定义的实数默认是双精度的, 要使用其他类型的,必须使用后缀
        //float n1 = 1.234f;
        //double n2 = 1.234;
        //decimal n3 = 1.234m;

        //Console.WriteLine(n1);
        //Console.WriteLine(n2);
        //Console.WriteLine(n3);

        //Console.WriteLine(n1.GetType());
        //Console.WriteLine(n2.GetType());
        //Console.WriteLine(n3.GetType());

        #endregion

        #region 5_枚举: 枚举默认从0开始

        Random r = new();
        Days day = (Days)(r.Next(0, 7));
        switch (day)
        {
            case Days.Monday:
                Console.WriteLine("It is Monday");
                break;
            case Days.Tuesday:
                Console.WriteLine("It is Tuesday");
                break;
            case Days.Wednesday:
                Console.WriteLine("It is Wednesday");
                break;
            case Days.Thursday:
                Console.WriteLine("It is Thursday");
                break;
            case Days.Friday:
                Console.WriteLine("It is Friday");
                break;
            case Days.Saturday:
                Console.WriteLine("It is Saturday");
                break;
            case Days.Sunday:
                Console.WriteLine("It is Sunday");
                break;
            default:
                Console.WriteLine("Invalid day"); // 都不满足的情况下, 默认的执行
                break;
        }
        foreach (int i in Enum.GetValues(typeof(Days)))
        {
            Console.WriteLine(i);
        }

        #endregion

        #region 6_元组

        //var words = ("sky", "blue", "rock", "fountain");
        //Console.WriteLine(words);
        //Console.WriteLine(words.Item1);

        //var words2 = (w1: "forest", w2: "deep", w3: "sea");
        //Console.WriteLine(words2.w1);
        //Console.WriteLine(words2.w2);
        //Console.WriteLine(words2.w3);

        #endregion

        #region 7_字符串和字符

        //string name = "Peter is running now!";
        //Console.WriteLine($"{name[0]}");

        #endregion

        #region 8_数组

        //int[] nums = new int[5];
        //nums[0] = 1;
        //nums[1] = 2;
        //nums[2] = 3;
        //nums[3] = 4;
        //nums[4] = 5;
        //Console.WriteLine(nums[0]);
        //for (int i = 0; i < nums.Length; i++)
        //{
        //    Console.WriteLine(nums[i]);
        //}

        #endregion

        #region 9_DateTime

        //DateTime now = DateTime.Now;
        //Console.WriteLine(now.Year);
        //Console.WriteLine(now.Month);
        //Console.WriteLine(now.Day);
        //Console.WriteLine(now.ToShortDateString());
        //Console.WriteLine(now.ToShortTimeString());

        #endregion

        #region 10_类型转换

        //int val1 = 0;
        //string val2 = "123";
        //sbyte val3 = 123;
        //val1 = Convert.ToInt32(val2);
        //val1 = (int)val3; // 显式转换(强制转换)
        //Console.WriteLine(val1.GetType());
        //Console.WriteLine(val2.GetType());
        // Console.WriteLine(12 + 12.5); // 隐式转
        // Console.WriteLine("12" + 12); // 隐式转

        #endregion

        #region 11_可空类型

        //Nullable<bool> male = null;
        //int? age = null; // 写法不同, 但是是上面代码的简写, 看起来有点typescript的味道了
        //Console.WriteLine(male.HasValue); // false
        //Console.WriteLine(age.HasValue); // false

        #endregion

        #region 12_转换&解析

        Console.WriteLine(Convert.ToBoolean(0.3));
        Console.WriteLine(Convert.ToBoolean(3));
        Console.WriteLine(Convert.ToBoolean(0));
        Console.WriteLine(Convert.ToBoolean(-1));

        Console.WriteLine(Convert.ToInt32("452"));
        Console.WriteLine(Convert.ToInt32(34.6)); // 小数位大于5时进位, 其他的话不进位, 和四舍五入还有点区别

        Console.WriteLine(Int32.Parse("34"));
        Console.WriteLine(Int32.Parse("-34"));
        Console.WriteLine(Int32.Parse("+34"));

        #endregion
    }
}